﻿using System;
using System.ComponentModel;
using System.Windows.Media.Effects;

namespace FunCam
{
    public class EffectEntry : INotifyPropertyChanged
    {
        private WeakReference _shader;

        #region Name (INotifyPropertyChanged Property)
        private string _name;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }
        #endregion

        #region ClassName (INotifyPropertyChanged Property)
        private string _className;

        public string ClassName
        {
            get { return _className; }
            set
            {
                _className = value;
                RaisePropertyChanged("ClassName");
            }
        }
        #endregion

        #region Shader (INotifyPropertyChanged Property)
        
        public ShaderEffect Shader
        {
            get {
                if( _shader == null || !_shader.IsAlive)
                {
                    _shader = new WeakReference(Activator.CreateInstance("FunCam", ClassName).Unwrap());
                }
                return _shader.Target as ShaderEffect;
            }
        }
        #endregion

        #region Thumbnail (INotifyPropertyChanged Property)
        private string _thumbnail;

        public string Thumbnail
        {
            get { return _thumbnail; }
            set
            {
                _thumbnail = value;
                RaisePropertyChanged("Thumbnail");
            }
        }
        #endregion
        
        #region INotifyPropertyChanged values

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

    }
}
